package com.example.sign;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.ColorSpace;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.DrawableRes;

public class Card extends FrameLayout {
    private TextView label;
    public Card(Context context) {
        super(context);

        label=new TextView(getContext());
        label.setTextSize(32);
        label.setGravity(Gravity.CENTER);
        label.setBackgroundColor(0x33ffffff);
        label.setTextColor(Color.argb(0, 0, 0, 0));




        LayoutParams lp=new LayoutParams(-1,-1);
        lp.setMargins(10,10,0,0);
        addView(label,lp);


        setNum(0);
    }
    private int num=0;

    public int getNum(){
        return  num;
    }
    public void setNum(int num){
        this.num=num;

        if(num<=0){
            label.setText("");
        }else{
            label.setText(num+"");
        }

        Resources resources = getContext().getResources();
        if(getNum()==0){
            label.setBackgroundColor(0x33ffffff);
        }else if(getNum()==2){
            Drawable btnDrawable = resources.getDrawable(R.drawable.sz2);
            label.setBackgroundDrawable(btnDrawable);

        }else if(getNum()==4){
            Drawable btnDrawable = resources.getDrawable(R.drawable.sz4);
            label.setBackgroundDrawable(btnDrawable);

        }else if(getNum()==8){
            Drawable btnDrawable = resources.getDrawable(R.drawable.sz8);
            label.setBackgroundDrawable(btnDrawable);

        }else if(getNum()==16){
            Drawable btnDrawable = resources.getDrawable(R.drawable.sz16);
            label.setBackgroundDrawable(btnDrawable);

        }else if(getNum()==32){
            Drawable btnDrawable = resources.getDrawable(R.drawable.sz32);
            label.setBackgroundDrawable(btnDrawable);

        }else if(getNum()==64){
            Drawable btnDrawable = resources.getDrawable(R.drawable.sz64);
            label.setBackgroundDrawable(btnDrawable);

        }else if(getNum()==128){
            Drawable btnDrawable = resources.getDrawable(R.drawable.sz128);
            label.setBackgroundDrawable(btnDrawable);

        }else if(getNum()==256){
            Drawable btnDrawable = resources.getDrawable(R.drawable.sz256);
            label.setBackgroundDrawable(btnDrawable);

        }else if(getNum()==512){
            Drawable btnDrawable = resources.getDrawable(R.drawable.sz512);
            label.setBackgroundDrawable(btnDrawable);

        }else if(getNum()==1024){
            Drawable btnDrawable = resources.getDrawable(R.drawable.sz1024);
            label.setBackgroundDrawable(btnDrawable);

        }else if(getNum()==2048){
            Drawable btnDrawable = resources.getDrawable(R.drawable.sz2048);
            label.setBackgroundDrawable(btnDrawable);

        }


    }
    public boolean equals(Card o){
        return getNum()==o.getNum();
    }

}
